package com.albaba.designpattern.singleton;

import java.io.*;


/**
 * @Description: TODO
 * @Author zx
 * @Date 2025/2/18 16:46
 * @Version 1.0
 */
public class Test_Singleton_006 {
    public static void main(String[] args) throws Exception {

        // 序列化对象输出流
        ObjectOutputStream outputStream = new ObjectOutputStream(new FileOutputStream("singleton.obj"));
        outputStream.writeObject(Singleton_007.getInstance());

        // 序列化对象输出流
        File file = new File("singleton.obj");
        ObjectInputStream inputStream = new ObjectInputStream(new FileInputStream(file));
        Singleton_007 instance = (Singleton_007) inputStream.readObject();

        System.out.println(instance);
        System.out.println(Singleton_007.getInstance());

        if (instance == Singleton_007.getInstance()) {
            System.out.println("单例");
        } else {
            System.out.println("非单例");
        }
    }
}
